from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from apps.goods.models import SKUImage, SKU
from apps.meiduo_admin.serializers.images import SKUImageSerializer, SKUSerializer
from apps.meiduo_admin.utils import UserPageNum


class ImageView(ModelViewSet):
    '''
        图片表的增删改查
    '''
    # 指定查询集
    queryset = SKUImage.objects.all()
    # 指定序列化器
    serializer_class = SKUImageSerializer
    # 指定分页器
    pagination_class = UserPageNum
    # 指定权限
    permission_classes = [IsAdminUser]

    # 自定义返回简单SKU数据方法
    def simple(self, request):
        skus = SKU.objects.all()
        s = SKUSerializer(skus, many=True)
        return Response(s.data)


